package main

import (
//    "fmt"
    "os"
    "time"
    "path/filepath"
)
const (
    DAYS = 168
    HOUR = 3
)

func walkFilter (path string, f os.FileInfo, err error) error {
    now := time.Now()
    if f == nil {
        return err
    }
    if f.IsDir(){
        return nil
    }
    //fmt.Println("file:", path)
    d := now.Sub(f.ModTime())
    if d.Hours() > DAYS {
        //fmt.Println(d.Hours())
        os.Remove(path)
    }
    return nil
}

/*
only at HOUR , delete old files
*/
func RemoveFiles(gid string) {
    go func (){
        for {
            n := time.Now()
            if n.Hour() ==  HOUR {
                filepath.Walk(gid, walkFilter)
            }
            time.Sleep(1 * time.Hour)
        }
    }()
}

/*
func main(){
    RemoveFiles("cc")
}
*/
